package cn.lili.modules.payment.entity.dto;

import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.StrUtil;
import cn.lili.common.vo.PageVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

/**
 * 搜索参数
 *
 * @author Chopper
 * @since 2021/3/17 6:08 下午
 */
@Data
public class OutOrderLogSearchParams extends PageVO {

    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "起始日期")
    private String startDate;

    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "结束日期")
    private String endDate;

    @ApiModelProperty(value = "二级商户号")
    private String subMchid;

    @ApiModelProperty(value = "订单单号")
    private String orderSn;

    /**
     * @see cn.lili.modules.order.order.entity.enums.ProfitSharingStatusEnum
     */
    @ApiModelProperty(value = "状态：PROCESSING：处理中,FINISHED：分账完成")
    private String status;

    public <T> QueryWrapper<T> queryWrapper() {
        QueryWrapper<T> wrapper = new QueryWrapper<>();

        //创建时间
        if (CharSequenceUtil.isNotBlank(startDate) && CharSequenceUtil.isNotBlank(endDate)) {
            wrapper.between("create_time", startDate, endDate);
        } else if (CharSequenceUtil.isNotBlank(startDate)) {
            wrapper.ge("create_time", startDate);
        } else if (CharSequenceUtil.isNotBlank(endDate)) {
            wrapper.le("create_time", endDate);
        }
        //账单号
        wrapper.like(CharSequenceUtil.isNotBlank(subMchid), "sub_mchid", subMchid);
        wrapper.eq(CharSequenceUtil.isNotBlank(status), "status", status);
        wrapper.eq(CharSequenceUtil.isNotBlank(orderSn), "order_sn", orderSn);
        return wrapper;
    }

}
